package com.fighYo.trace.config.handler;

import com.fighYo.trace.utils.R;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {

    //自定义异常
    @ExceptionHandler(TraceException.class)
    @ResponseBody //为了返回数据
    public R error(TraceException e) {
        e.printStackTrace();
        return R.error().code(e.getCode()).msg(e.getMsg());
    }
}
